import streamlit as st
from authentication import load_config, save_config

def system_config_page():
    """系统基础配置页面"""
    st.title("系统基础配置")

    config = load_config()

    with st.form("system_settings"):
        password_expiry = st.number_input(
            "密码有效期（天）",
            min_value=1,
            max_value=365,
            value=config["system_settings"].get("password_expiry_days", 90),
            help="设置密码的有效期限，超过此期限用户需要修改密码"
        )

        max_login_attempts = st.number_input(
            "登录错误锁定阈值（次）",
            min_value=1,
            max_value=10,
            value=config["system_settings"].get("max_login_attempts", 5),
            help="用户连续登录失败达到此次数后，账号将被锁定"
        )

        password_criteria = st.text_input(
            "密码要求",
            value=r"^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,20}$",
            disabled=True
        )

        if st.form_submit_button("保存设置"):
            config["system_settings"].update({
                "password_expiry_days": int(password_expiry),
                "max_login_attempts": int(max_login_attempts)
            })
            save_config(config)
            st.success("设置已保存")
